package com.ruoyi.admin.controller;

import com.ruoyi.admin.service.IRewardService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.Reward;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 奖品录入Controller
 * 
 * @author xukai
 * @date 2024-12-22
 */
@RestController
@RequestMapping("/reward/reward")
public class RewardController extends BaseController
{
    @Autowired
    private IRewardService rewardService;

    /**
     * 查询奖品录入列表
     */
    //@PreAuthorize("@ss.hasPermi('reward:reward:list')")
    @GetMapping("/list")
    public TableDataInfo list(Reward reward)
    {
        startPage();
        List<Reward> list = rewardService.selectRewardList(reward);
        return getDataTable(list);
    }

    /**
     * 导出奖品录入列表
     */
    //@PreAuthorize("@ss.hasPermi('reward:reward:export')")
    @Log(title = "奖品录入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reward reward)
    {
        List<Reward> list = rewardService.selectRewardList(reward);
        ExcelUtil<Reward> util = new ExcelUtil<Reward>(Reward.class);
        util.exportExcel(response, list, "奖品录入数据");
    }

    /**
     * 获取奖品录入详细信息
     */
    //@PreAuthorize("@ss.hasPermi('reward:reward:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rewardService.selectRewardById(id));
    }

    /**
     * 新增奖品录入
     */
    //@PreAuthorize("@ss.hasPermi('reward:reward:add')")
    @Log(title = "奖品录入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reward reward)
    {
        return toAjax(rewardService.insertReward(reward));
    }

    /**
     * 修改奖品录入
     */
    //@PreAuthorize("@ss.hasPermi('reward:reward:edit')")
    @Log(title = "奖品录入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reward reward)
    {
        return toAjax(rewardService.updateReward(reward));
    }

    /**
     * 删除奖品录入
     */
    //@PreAuthorize("@ss.hasPermi('reward:reward:remove')")
    @Log(title = "奖品录入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rewardService.deleteRewardByIds(ids));
    }
}
